package com.sskj.mine.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.VerifyGoogleActivity;
import com.sskj.mine.bean.GoogleCode;
import com.sskj.mine.http.HttpConfig;


public class VerifyGoogleActivityPresenter extends BasePresenter<VerifyGoogleActivity> {
    public void submit(int openCLose,String type, String account, String authCode, String googleAuthCode) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + "/home/google/checkGoogleCommand")
                .params("account", account)
                .params("type", type)
                .params("code", authCode)
                .params("dyGoodleCommand", googleAuthCode)
                .execute(new JsonCallBack<HttpData<Object>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
                        toggleGoogleVerify(openCLose, googleAuthCode, authCode, account);
                    }
                });
    }

    public void requestAuthCode(String account) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
                .params("mobile", account)
                .params("type", 3)
                .execute(new JsonCallBack<HttpData>(this, true) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getStatus() == 200) {
//                            ToastUtil.getInstance(MyAppLication.getApplication()).showMessage(response.body().getMsg());
                            mView.onAuthCodeSuccess();
                        } else {
                            ToastUtil.showShort(httpListData.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                    }
                });

    }

    public void requestData() {
        OkGo.<HttpData<GoogleCode>>get(HttpConfig.BASE_URL + "/Home/Google/createGoogleCommand")
                .execute(new JsonCallBack<HttpData<GoogleCode>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<GoogleCode>> response) {
                        mView.onGoogleCodeSuccess(response.body().getData());
                    }

                });
    }

    public void sendEmail() {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
//                        ToastUtil.getInstance(MyAppLication.getApplication()).showMessage(response.body().getMsg());
                        mView.onAuthCodeSuccess();
                    }
                });
    }

    // 开启谷歌认证
    public void toggleGoogleVerify(int googleType, String code, String mobileCode, String mobile) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.SET_GOOGLE_VERIFY)
                .params("act", googleType)
                .params("dyGoodleCommand", code)
                .params("code", mobileCode)
                .params("mobile", mobile)
                .execute(new JsonCallBack<HttpData<Object>>() {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
                        mView.onBindSuccess();
                    }
                });
    }
}
